package com.zmc.product.exception.handler;

import com.zmc.common.utils.R;
import com.zmc.product.exception.ProductNotExistException;
import com.zmc.product.exception.ProductSkuException;
import com.zmc.product.exception.ProductStatusException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author：zmc
 * @Date：2024/11/11 15:32
 */

@ControllerAdvice
@ResponseBody
public class ProductExceptionHandler {

    @ExceptionHandler(value = ProductNotExistException.class)
    public R rroductNotExistExceptionHandler(ProductNotExistException exception, HttpServletRequest request) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = ProductStatusException.class)
    public R productStatusExceptionHandler(ProductStatusException exception, HttpServletRequest request) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }

    @ExceptionHandler(value = ProductSkuException.class)
    public R productSkuExceptionHandler(ProductSkuException exception, HttpServletRequest request) {
        return R.error(exception.getErrorCode().getCode(), exception.getMessage());
    }
}
